/*******************************************************************************
 * Copyright (c) 2011 Bruno Quoitin.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Bruno Quoitin - initial API and implementation
 ******************************************************************************/
package reso.examples.gobackn.transport;

import reso.common.Message;
import reso.ip.IPAddress;

public class DummyPacket implements Message {

	private String type;
	private String payload;
	private PortInterface portSrc;
	private PortInterface portDest;
	private int protocol;
	private int sequenceNumber;

	public DummyPacket(int sequenceNumber, String type, PortInterface portSrc,
			PortInterface portDest, int protocol, String payload) {
		this.sequenceNumber = sequenceNumber;
		this.type = type;
		this.portSrc = portSrc;
		this.portDest = portDest;
		this.protocol = protocol;
		this.payload = payload;
	}

	public String getType() {
		return type;
	}

	public String getPayload() {
		return payload;
	}

	public PortInterface getPortSrc() {
		return portSrc;
	}

	public PortInterface getPortDest() {
		return portDest;
	}

	public int getProtocol() {
		return protocol;
	}

	public int getSequenceNumber() {
		return sequenceNumber;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((portDest == null) ? 0 : portDest.hashCode());
		result = prime * result + ((portSrc == null) ? 0 : portSrc.hashCode());
		result = prime * result + protocol;
		result = prime * result + sequenceNumber;
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		DummyPacket other = (DummyPacket) obj;
		if (portDest == null) {
			if (other.portDest != null)
				return false;
		} else if (!portDest.equals(other.portDest))
			return false;
		if (portSrc == null) {
			if (other.portSrc != null)
				return false;
		} else if (!portSrc.equals(other.portSrc))
			return false;
		if (protocol != other.protocol)
			return false;
		if (sequenceNumber != other.sequenceNumber)
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "DummyPacket [type=" + type + ", sequenceNumber="
				+ sequenceNumber + "]";
	}

}
